package com.pzb.web.controller.order;

import java.util.List;

import com.pzb.rabbitmq.RabbitMqModel;
import com.pzb.rabbitmq.RabbitMqSender;
import com.pzb.wechat.service.IWechatAppletService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pzb.common.annotation.Log;
import com.pzb.common.core.controller.BaseController;
import com.pzb.common.core.domain.AjaxResult;
import com.pzb.common.enums.BusinessType;
import com.pzb.order.domain.OdOrder;
import com.pzb.order.service.IOdOrderService;
import com.pzb.common.core.page.TableDataInfo;

/**
 * 订单管理Controller
 * 
 * @author Mr_Wu
 * @date 2021-12-15
 */
@RestController
@RequestMapping("/order/order")
public class OdOrderController extends BaseController
{
    @Autowired
    private IOdOrderService odOrderService;
    @Autowired
    private IWechatAppletService wechatAppletService;

    /**
     * 查询订单管理列表
     */
    @PreAuthorize("@ss.hasPermi('order:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(OdOrder odOrder)
    {
        startPage();
        odOrder.setExtAppid(wechatAppletService.getExtAppid());
        if("00".equals(odOrder.getOrderStatus())){
            odOrder.setOrderStatus("0");
            odOrder.setPayStatus("0");
        }else if("01".equals(odOrder.getOrderStatus())){
            odOrder.setOrderStatus("0");
            odOrder.setPayStatus("1");
        }
        List<OdOrder> list = odOrderService.selectOdOrderList(odOrder);
        return getDataTable(list);
    }

    /**
     * 获取订单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(odOrderService.selectOdOrderById(id));
    }

    /**
     * 获取订单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:order:query')")
    @GetMapping(value = "/getDetail/{id}")
    public AjaxResult getDetail(@PathVariable("id") Long id)
    {
        return AjaxResult.success(odOrderService.selectOrderDetailById(id));
    }


    /**
     * 修改订单管理
     */
    @PreAuthorize("@ss.hasPermi('order:order:edit')")
    @Log(title = "订单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OdOrder odOrder)
    {
        return toAjax(odOrderService.updateOdOrder(odOrder));
    }
    /**
     * 修改订单管理
     */
    @PreAuthorize("@ss.hasPermi('order:order:edit')")
    @Log(title = "订单管理", businessType = BusinessType.UPDATE)
    @PutMapping("/sendGoods")
    public AjaxResult sendGoods(@RequestBody OdOrder odOrder)
    {
        return toAjax(odOrderService.sendGoods(odOrder));
    }


    /**
     * 取消订单
     */
    @PreAuthorize("@ss.hasPermi('order:order:edit')")
    @GetMapping(value = "/cancelOrder/{id}")
    public AjaxResult cancelOrder(@PathVariable("id") Long id)
    {
        return toAjax(odOrderService.cancelOrder(id));
    }

    /**
     * 首页数据汇总
     * @return
     */
    @GetMapping(value = "/orderDataCount")
    public AjaxResult orderDataCount()
    {
        return odOrderService.orderDataCount(wechatAppletService.getExtAppid());
    }


}
